import sqlite3 from "sqlite3";
import { open } from "sqlite";
import * as path from "path";
import { Episode } from "../type";

const dbPath = path.join(__dirname, "..", "..", "db", "db.db");

const db = await open({
  filename: dbPath,
  driver: sqlite3.Database,
});

export const add = async ({
  episode_cn,
  episode_jp,
  time,
  titile_cn,
  title_jp,
  commic,
}: Episode) => {
  const sql = `INSERT INTO "main"."t_conan" ("episode_jp", "episode_cn", "title_jp", "titile_cn", "time", "commic") VALUES  (${episode_jp}, '${episode_cn}', '${title_jp}', '${titile_cn}', '${time}', '${commic}')`;

  try {
    const data = await db.run(sql);
  } catch (error) {
    console.error(`报错sql:${sql}`);
    throw Error(`报错sql:${error}`);
  }
};
